/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.sql.*;
import java.util.*;

/**
 *
 * @author sio
 */
public class DAO {

    public static Collection<Dep> getLesDeps() {
        Collection<Dep> lesDeps = new TreeSet<Dep>();
        Connection con = Connect.get();
        Statement req;

        try {
            req = con.createStatement();

            ResultSet rs = req.executeQuery("select distinct departement from medecin;");
            while (rs.next()) {
                Dep d = new Dep(rs.getString("departement"));
                lesDeps.add(d);
            }
        } catch (SQLException e) {
            System.out.println("Erreur SQL :" + e);
        }
        return lesDeps;
    }

    public static Collection<Spe> getLesSpes() {
        Collection<Spe> lesSpes = new TreeSet<Spe>();
        Connection con = Connect.get();
        Statement req;
        try {
            req = con.createStatement();

            ResultSet rs = req.executeQuery("select distinct specialitecomplementaire as spe from medecin;");
            while (rs.next()) {
                if (rs.getString("spe") != null) {
                    Spe s = new Spe(rs.getString("spe"));
                    lesSpes.add(s);
                }
            }
        } catch (SQLException e) {
            System.out.println("Erreur SQL :" + e);
        }
        return lesSpes;
    }

    public static Collection<Med> getLesMeds() {
        Statement req;
        Collection<Med> lesMeds = new TreeSet<Med>();
        Connection con = Connect.get();
        try {
            req = con.createStatement();
            ResultSet rs = req.executeQuery("select nom, prenom, adresse, tel, specialitecomplementaire as spe,departement, id from medecin");

            while (rs.next()) {
                Med m = new Med(rs.getString("nom"), rs.getString("prenom"),
                        rs.getString("adresse"), rs.getString("tel"), rs.getString("spe"), rs.getString("departement"),
                        rs.getString("id"));
                lesMeds.add(m);
            }
        } catch (SQLException e) {
            System.out.println("Erreur SQL :" + e);
        }
        return lesMeds;
    }
}
